gtk-demo/gltransition: Replace fire background with more mellow blobs
authorAlexander Larsson <alexl@redhat.com>
Wed, 30 Sep 2020 14:26:03 +0000 (16:26 +0200)
committerAlexander Larsson <alexl@redhat.com>
Wed, 30 Sep 2020 14:38:50 +0000 (16:38 +0200)
demos/gtk-demo/background.glsl [new file with mode: 0644]
demos/gtk-demo/demo.gresource.xml
demos/gtk-demo/fire.glsl [deleted file]
demos/gtk-demo/gltransition.c

diff --git a/demos/gtk-demo/background.glsl b/demos/gtk-demo/background.glsl
new file mode 100644 (file)
index 0000000..b807935
--- /dev/null
@@ -0,0 +1,26 @@
+uniform float u_time;
+
+void
+mainImage(out vec4 fragColor, in vec2 fragCoord, in vec2 resolution, in vec2 uv)
+{
+  vec2 pos = (fragCoord.xy * 2.0 - resolution.xy)/ min (resolution.x, resolution.y) ;
+
+  float t0 = sin ((u_time + 0.00)*1.0);
+  float t1 = sin ((u_time + 0.30)*0.4);
+  float t2 = cos ((u_time + 0.23)*0.9);
+  float t3 = cos ((u_time + 0.41)*0.6);
+  float t4 = cos ((u_time + 0.11)*0.3);
+
+  vec2 p0 = vec2 (t1, t0) ;
+  vec2 p1 = vec2 (t2, t3) ;
+  vec2 p2 = vec2 (t4, t3) ;
+
+  float r = 1.0/distance (pos, p0);
+  float g = 1.0/distance (pos, p1);
+  float b = 1.0/distance (pos, p2);
+  float sum = r + g + b;
+
+  float alpha = 1.0 - pow (1.0/(sum), 40)*pow (10.0, 40*0.7);
+
+  fragColor = vec4 (r*0.5, g*0.5, b*0.5, 1.0) * alpha;
+}
index d279d08af58111825eaf0be8b00a45ee77126338..2b7cdc0a8a5f3b23fc6998aa5210311042492b61 100644 (file)
     <file>gtkshaderbin.h</file>
     <file>gtkshaderbin.c</file>
     <file>ripple.glsl</file>
-    <file>fire.glsl</file>
+    <file>background.glsl</file>
    <file>transition1.glsl</file>
     <file>transition2.glsl</file>
     <file>transition3.glsl</file>
diff --git a/demos/gtk-demo/fire.glsl b/demos/gtk-demo/fire.glsl
deleted file mode 100644 (file)
index 1992688..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-uniform float u_time;
-
-/* 2D -> [0..1] random number generator */
-float random(vec2 st) {
-  return fract(sin(dot(st.xy,
-                       vec2(12.9898,78.233))) *
-               43758.5453123);
-}
-
-/* Generate a smoothed 2d noise based on random() */
-float noise(vec2 v) {
-  /* Round point v to integer grid grid */
-  vec2 grid_point = floor(v);
-  /* Randomize in grid corners */
-  float corner1 = random(grid_point);
-  float corner2 = random(grid_point + vec2(1, 0));
-  float corner3 = random(grid_point + vec2(0, 1));
-  float corner4 = random(grid_point + vec2(1, 1));
-  /* Interpolate smoothly between grid points */
-  vec2 fraction = smoothstep(vec2(0.0), vec2(1.0), fract(v));
-  return mix(mix(corner1, corner2, fraction.x),
-             mix(corner3, corner4, fraction.x),
-             fraction.y);
-}
-
-/* fractal brownian motion noice, see https://www.iquilezles.org/www/articles/fbm/fbm.htm */
-float fbm(in vec2 x)
-{
-  const float octaveScale = 1.9;
-  const float G = 0.5;
-  float f = 1.0;
-  float a = 1.0;
-  float t = 0.0;
-  int numOctaves = 5;
-  for (int i = 0; i < numOctaves; i++) {
-    t += a*noise(f*x);
-    f *= octaveScale;
-    a *= G;
-  }
-
-  return t;
-}
-
-void mainImage(out vec4 fragColor, in vec2 fragCoord, in vec2 resolution, in vec2 uv)
-{
-  vec2 xy = fragCoord / resolution;
-
-  float zoom = 3.0 - sin(u_time*0.5)*0.3;
-
-  // Normalize coord to height of widget
-  vec2 p = (vec2 (-resolution.x/2.0 + fragCoord.x, resolution.y - fragCoord.y) / resolution.yy)* zoom;
-
-    // Use recursive incantations of fbm
-  float q1 = fbm(p - vec2(0.8, 0.3) * u_time);
-  float q2 = fbm(p - vec2(0.5, 1.3) * u_time);
-  float r = fbm(2.0*p + vec2(q1,q2) - vec2(0.0, 1.0)*u_time*10.0 *0.4);
-
-  // Compute intensity, mostly on the bottom
-  float w = 2.0 * r * p.y;
-
-  // Smooth out left/right side and fade in at start
-  w /= smoothstep(0.0,0.1, xy.x)* smoothstep(0.0,0.1, 1.0-xy.x) *  smoothstep(0.0,0.4, u_time);
-
-  // Compute colors
-  vec3 c = vec3(1.0,.2,.05);
-  vec3 color = 1.0 / (w*w/c + 1.0);
-
-  // Mix in widget
-  fragColor = gsk_premultiply(vec4(color, color.x));
-}
index 9977a317f44356b7820c543416053903834464c0..c80b3fcc2b770f98ad6b8fd933c71d8b6f6ad002 100644 (file)
@@ -294,7 +294,7 @@ create_gltransition_window (GtkWidget *do_widget)
   outer_grid = gtk_grid_new ();
   gtk_window_set_child (GTK_WINDOW (window), outer_grid);
 
-  paintable = gsk_shader_paintable_new (gsk_gl_shader_new_from_resource ("/gltransition/fire.glsl"), NULL);
+  paintable = gsk_shader_paintable_new (gsk_gl_shader_new_from_resource ("/gltransition/background.glsl"), NULL);
   background = gtk_picture_new_for_paintable (paintable);
   gtk_widget_add_tick_callback (background, update_paintable, NULL, NULL);